package com.dianping.cat.consumer.business.model.transform;

import com.dianping.cat.consumer.business.model.IEntity;
import com.dianping.cat.consumer.business.model.IVisitor;
import com.dianping.cat.consumer.business.model.entity.BusinessItem;
import com.dianping.cat.consumer.business.model.entity.BusinessReport;
import com.dianping.cat.consumer.business.model.entity.Segment;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  13 */   private Stack<Object> m_objs = new Stack();

  private BusinessReport m_businessReport;


  public DefaultMerger() {}

  public DefaultMerger(BusinessReport businessReport) {
/*  21 */     this.m_businessReport = businessReport;
/*  22 */     this.m_objs.push(businessReport);
  }


/*  26 */   public BusinessReport getBusinessReport() { return this.m_businessReport; }



/*  30 */   protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  34 */     this.m_objs.push(to);
/*  35 */     from.accept(this);
    this.m_objs.pop();
  }


/*  40 */   protected void mergeBusinessItem(BusinessItem to, BusinessItem from) { to.mergeAttributes(from); }



/*  44 */   protected void mergeBusinessReport(BusinessReport to, BusinessReport from) { to.mergeAttributes(from); }



/*  48 */   protected void mergeSegment(Segment to, Segment from) { to.mergeAttributes(from); }



  public void visitBusinessItem(BusinessItem from) {
/*  53 */     BusinessItem to = (BusinessItem)this.m_objs.peek();

/*  55 */     mergeBusinessItem(to, from);
/*  56 */     visitBusinessItemChildren(to, from);
  }

  protected void visitBusinessItemChildren(BusinessItem to, BusinessItem from) {
/*  60 */     for (Segment source : from.getSegments().values()) {
/*  61 */       Segment target = to.findSegment(source.getId());

/*  63 */       if (target == null) {
/*  64 */         target = new Segment(source.getId());
/*  65 */         to.addSegment(target);
      }

/*  68 */       this.m_objs.push(target);
/*  69 */       source.accept(this);
/*  70 */       this.m_objs.pop();
    }
  }


  public void visitBusinessReport(BusinessReport from) {
/*  76 */     BusinessReport to = (BusinessReport)this.m_objs.peek();

    mergeBusinessReport(to, from);
/*  79 */     visitBusinessReportChildren(to, from);
  }

  protected void visitBusinessReportChildren(BusinessReport to, BusinessReport from) {
/*  83 */     for (BusinessItem source : from.getBusinessItems().values()) {
/*  84 */       BusinessItem target = to.findBusinessItem(source.getId());

/*  86 */       if (target == null) {
/*  87 */         target = new BusinessItem(source.getId());
/*  88 */         to.addBusinessItem(target);
      }

/*  91 */       this.m_objs.push(target);
/*  92 */       source.accept(this);
/*  93 */       this.m_objs.pop();
    }
  }


  public void visitSegment(Segment from) {
/*  99 */     Segment to = (Segment)this.m_objs.peek();

/* 101 */     mergeSegment(to, from);
/* 102 */     visitSegmentChildren(to, from);
  }

  protected void visitSegmentChildren(Segment to, Segment from) {}
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-consumer-3.0.0.jar!/com/dianping/cat/consumer/business/model/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */